package test13;

import java.text.DecimalFormat;
import java.util.Scanner;

public class Averaging {
    private double a;
    private double b;
    private double c;
    public Averaging() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请依次输入每个数字并按回车,最后输入任意数字表示结束");
        double a = sc.nextDouble();
        System.out.println("已输入a");
        if(sc.hasNextDouble()){
            this.a = a;

        }
        else {
            System.out.println("请输入正确的a");
        }
        double b = sc.nextDouble();
        System.out.println("已输入b");
        if(sc.hasNextDouble()){

            this.b = b;

        }
        else {
            System.out.println("请输入正确的b");
        }
        double c = sc.nextDouble();
        System.out.println("已输入c");
        System.out.println("输入任意数字即可求平均数");
        if(sc.hasNextDouble()){
            this.c = c;

        }
        else {
            System.out.println("请输入正确的c");
        }
    }
    public void avera(){

        double averag;
        averag = (a+b+c)/3;
        System.out.println("a:"+a);
        System.out.println("b:"+b);
        System.out.println("c:"+c);
        DecimalFormat df = new DecimalFormat("0.000");
        System.out.println("这三个数的平均数是："+df.format(averag));
    }



}
//从键盘输入三个变量a、b和c的值，求三个数的平均值存入变量average中，(精确到三位小数)，输出运算结果。
